<template>
  <div class="totalhub">
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/index' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>金额管理</el-breadcrumb-item>
      <el-breadcrumb-item>金额流水</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card class="box_card">
      <!-- 顶部搜索区域 -->
      <el-row :gutter="20">
        <el-col :span="8">
          <el-input
            class="input-with-select"
            placeholder="车牌号搜索"
            v-model="car_number_search"
          >
            <el-button
              slot="append"
              icon="el-icon-search"
              @click="carnumber()"
            ></el-button>
          </el-input>
        </el-col>
      </el-row>
      <!-- 金额流水列表区 -->
      <el-table :data="totallist" border stripe class="tabel_box">
        <el-table-column type="index" label="#"></el-table-column>
        <el-table-column label="车牌号" prop="car_number"></el-table-column>
        <el-table-column label="交易时间" prop="time"></el-table-column>
        <el-table-column label="交易金额" prop="money"></el-table-column>
        <el-table-column label="备注" prop="remarks"></el-table-column>
      </el-table>
      <!-- 分页区 -->
      <div class="page_box" v-if="ispage">
        <el-pagination
          :background="true"
          :page-count="pager_count"
          @current-change="handleCurrentChange"
          :layout="col"
          :total="count_total"
        >
        </el-pagination>
      </div>
    </el-card>
  </div>
</template>

<script>
export default {
  data() {
    return {
      totallist: [], //金额列表
      car_number_search: "", //车牌号搜索
      pager_count: 1, // 当前页码
      count_total: 0, // 总页数
      col: "prev, pager, next, jumper,slot", //开启的配置
      ispage: true, // 是否显示分页
    };
  },
  mounted() {
    this.gettotalInfo(); //获取金额流水列表
  },
  watch: {
    // 如果只有1页，则不显示分页按钮
    count_total(newVal) {
      if (newVal <= 10) {
        this.ispage = false;
      }
    },
  },
  methods: {
    funorderinfo(parameter) {
      this.$getapi("/total/get", parameter, "json")
        .then((res) => {
          if (res.code === 200) {
            this.totallist = res.data;
            this.count_total = res.count * 10;
          } else {
            this.$message.error(res.msg);
          }
        })
        .catch((error) => {
          this.$message.error(error);
        });
    },
    // 获取金额流水列表
    gettotalInfo() {
      let par = {
        page: this.pager_count,
      };
      this.funorderinfo(par);
    },
    // 车牌号搜索
    carnumber() {
      let par = { car_number: this.car_number_search };
      this.funorderinfo(par);
    },
    // 页数跳转
    handleCurrentChange(val) {
      this.pager_count = val;
      this.getorderInfo();
    },
  },
};
</script>

<style lang="less" scoped>
.totalhub {
  .box_card {
    margin-top: 20px;
    .tabel_box {
      font-size: 14px;
    }
    .page_box {
      margin-top: 20px;
    }
  }
  .el-row {
    margin-bottom: 10px;
  }
}
</style>